#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(voif)
{
    pid_t pid;
    int ret;

    if((pid = fork()) < 0)
    {
      perror("fork error");
      exit(1);
    }
    if(pid == 0)
    {
      //use raise function to send the SIGSTOP signal in the subprocess
        printf("subprocess was stoped in subprocess\n");
       raise(SIGSTOP);
        exit(0);
    }
    else
    {
        //Collecte the signal that signaled by subprocess in the parent process,and  invoke the  kill function for the corresponding operation 
        printf("pid=%d\n",pid);
        printf("waiting for subprocess to exit.... \n");
         printf("sleeping now\n");
        sleep(2);        
        
        if((waitpid(pid,NULL,WNOHANG)) == 0)
        //if((waitpid(pid,NULL,0)) == 0)
        {

            if((ret = kill(pid, SIGKILL)) == 0) 
              printf("kill %d\n",pid);
            else
              perror("kill error");
        }
        else
        {
            printf("waitpid error\n"); 
        }
    }

}
